(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  define(['views/base/view', 'views/base/form_view', 'text!templates/user/login.html'], function(View, FormView, template) {
    'use strict';
    var LoginView, _ref;
    return LoginView = (function(_super) {
      __extends(LoginView, _super);

      function LoginView() {
        _ref = LoginView.__super__.constructor.apply(this, arguments);
        return _ref;
      }

      LoginView.prototype.template = template;

      LoginView.prototype.autoRender = true;

      LoginView.prototype.id = 'login-view';

      LoginView.prototype.events = {
        'submit #form-login': 'submitFormHandler'
      };

      LoginView.prototype.cacheDOMElements = function() {
        return this.DOMElements = {
          $formLogin: this.$('#form-login'),
          $username: this.$('#username'),
          $password: this.$('#password')
        };
      };

      LoginView.prototype.afterRender = function() {
        LoginView.__super__.afterRender.apply(this, arguments);
        return this.DOMElements.$formLogin.validate({
          rules: {
            username: {
              required: true
            },
            password: {
              required: true
            }
          }
        });
      };

      LoginView.prototype.disableActions = function() {
        var $el;
        $el = this.$form || this.$el;
        if ($el) {
          return $el.find('button, a, .btn, select, input, i, textarea').attr('disabled', true).addClass('disabled');
        }
      };

      LoginView.prototype.enableActions = function() {
        var $el;
        $el = this.$form || this.$el;
        if ($el) {
          $el.find('button, a, .btn, select, input, i, textarea').removeAttr('disabled').removeClass('disabled');
        }
        return this.DOMElements.$formLogin.find('button[type="submit"]').text('Continuar');
      };

      LoginView.prototype.submitFormHandler = function(event) {
        var formData;
        event.preventDefault();
        formData = {
          username: this.DOMElements.$username.val().toLowerCase(),
          password: this.DOMElements.$password.val()
        };
        this.DOMElements.$formLogin.find('button[type="submit"]').text('Verificando credênciais...');
        this.disableActions();
        return this.trigger('signin', formData);
      };

      return LoginView;

    })(View);
  });

}).call(this);
